<template>
  <main class="main-content" :class="currentTheme">
    <div class="page-header">
      <div class="container">
        <h1 class="page-title">用户中心</h1>
        <p class="page-description">管理您的订单、收藏和点赞内容</p>
      </div>
    </div>
    
    <div class="container">
      <div class="user-center-layout">
        <aside class="sidebar">
          <div class="user-info">
            <div class="user-avatar" @click="showAvatarModal = true">
              <img src="@/assets/User.jpg" alt="用户头像">
              <div class="avatar-edit-overlay">
                <span>更换</span>
              </div>
            </div>
            <div class="user-details">
              <h3 class="user-name">温酒书生</h3>
              <p class="user-points">积分: 999</p>
              <p class="user-level">普通会员</p>
            </div>
          </div>
          
          <nav class="sidebar-nav">

   <router-link to="/user/settings" class="sidebar-link">
              <span class="link-icon">🔧</span>
              <span>账户设置</span>
            </router-link>

            <router-link to="/user/orders" class="sidebar-link">
              <span class="link-icon">📦</span>
              <span>我的订单</span>
            </router-link>
            <router-link to="/user/shoucang" class="sidebar-link">
              <span class="link-icon">❤️</span>
              <span>我的收藏</span>
            </router-link>
            <router-link to="/user/dianzan" class="sidebar-link">
              <span class="link-icon">👍</span>
              <span>我的点赞</span>
            </router-link>
         
            <a href="#" class="sidebar-link">
              <span class="link-icon">💬</span>
              <span>我的消息</span>
            </a>
          </nav>
        </aside>
        
        <div class="content-area">
          <router-view />
        </div>
      </div>
    </div>
    
    <!-- 头像设置弹窗 -->
    <div class="modal-overlay" v-if="showAvatarModal" @click="showAvatarModal = false">
      <div class="modal-content" @click.stop>
        <h3 class="modal-title">更换头像</h3>
        <div class="avatar-options">
          <div 
            v-for="(avatar, index) in avatarOptions" 
            :key="index" 
            class="avatar-option"
            :class="{ 'selected': tempAvatar === avatar }"
            @click="selectAvatar(avatar)"
          >
            <img :src="avatar" alt="头像选项">
          </div>
        </div>
        <div class="avatar-upload">
          <label for="avatar-upload" class="upload-label">上传自定义头像</label>
          <input type="file" id="avatar-upload" accept="image/*" @change="handleAvatarUpload" class="upload-input">
        </div>
        <div class="modal-actions">
          <button class="btn-outline" @click="showAvatarModal = false">取消</button>
          <button class="btn-primary" @click="saveAvatar">保存</button>
        </div>
      </div>
    </div>
  </main>
</template>

<script>
export default {
  name: 'UserCenterLayout',
  data() {
    return {
      showAvatarModal: false,
      userAvatar: '@/assets/User.jpg',
      tempAvatar: '',
      avatarOptions: [
        'https://via.placeholder.com/80/e75480',
        'https://via.placeholder.com/80/5d8aa8',
        'https://via.placeholder.com/80/50c878',
        'https://via.placeholder.com/80/ffbf00',
        'https://via.placeholder.com/80/9966cc',
        'https://via.placeholder.com/80/f08080'
      ],
      currentTheme: 'theme-pink-blue' // 默认主题
    };
  },
  methods: {
    selectAvatar(avatar) {
      this.tempAvatar = avatar;
    },
    handleAvatarUpload(event) {
      const file = event.target.files[0];
      if (file) {
        const reader = new FileReader();
        reader.onload = (e) => {
          this.tempAvatar = e.target.result;
        };
        reader.readAsDataURL(file);
      }
    },
    saveAvatar() {
      if (this.tempAvatar) {
        this.userAvatar = this.tempAvatar;
        this.tempAvatar = '';
      }
      this.showAvatarModal = false;
    }
  }
};
</script>

<style scoped>
.main-content {
  flex: 1;
  background: linear-gradient(45deg, #D693A1, #E2F5FF);
  min-height: 100vh;
  padding-top: 70px; /* 为固定头部留出空间 */
}

/* 主题样式 */
.theme-pink-blue {
  background: linear-gradient(45deg, #D693A1, #E2F5FF);
}

.theme-purple {
  background: linear-gradient(45deg, #9966CC, #E0B0FF);
}

.theme-gray {
  background: linear-gradient(45deg, #808080, #D3D3D3);
}

.theme-blue {
  background: linear-gradient(45deg, #5D8AA8, #B0E0E6);
}

.page-header {
  background-color: rgba(255, 255, 255, 0.7);
  padding: 2rem 0;
  text-align: center;
  margin-bottom: 2rem;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.page-title {
  color: #e75480;
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.page-description {
  color: #666;
  font-size: 1.1rem;
}

.user-center-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  margin-bottom: 3rem;
}

.sidebar {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.user-info {
  padding: 2rem;
  background-color: rgba(231, 84, 128, 0.1);
  display: flex;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid white;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
  cursor: pointer;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-edit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  opacity: 0;
  transition: opacity 0.3s;
}

.user-avatar:hover .avatar-edit-overlay {
  opacity: 1;
}

.user-name {
  font-size: 1.2rem;
  margin-bottom: 0.3rem;
  color: #333;
}

.user-points {
  color: #e75480;
  font-weight: bold;
  margin-bottom: 0.3rem;
}

.user-level {
  color: #e75480;
  font-size: 0.9rem;
  background-color: rgba(231, 84, 128, 0.1);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  display: inline-block;
}

.sidebar-nav {
  padding: 1.5rem 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 1rem 1.5rem;
  color: #555;
  text-decoration: none;
  transition: all 0.3s;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background-color: rgba(231, 84, 128, 0.05);
  color: #e75480;
}

.sidebar-link.router-link-active {
  background-color: rgba(231, 84, 128, 0.1  84, 128, 0.05);
  color: #e75480;
}

.sidebar-link.router-link-active {
  background-color: rgba(231, 84, 128, 0.1);
  color: #e75480;
  border-left-color: #e75480;
}

.link-icon {
  margin-right: 0.8rem;
  font-size: 1.2rem;
}

.content-area {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  padding: 2rem;
  min-height: 600px;
}

/* 弹窗样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  border-radius: 12px;
  padding: 2rem;
  width: 90%;
  max-width: 500px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-title {
  color: #e75480;
  margin-bottom: 1.5rem;
  text-align: center;
}

.avatar-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.avatar-option {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all 0.3s;
  margin: 0 auto;
}

.avatar-option img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-option:hover {
  transform: scale(1.05);
}

.avatar-option.selected {
  border-color: #e75480;
}

.avatar-upload {
  margin-bottom: 1.5rem;
  text-align: center;
}

.upload-label {
  display: inline-block;
  padding: 0.8rem 1.5rem;
  background-color: #f8f8f8;
  border: 1px dashed #ddd;
  border-radius: 4px;
  cursor: pointer;
  color: #666;
  transition: all 0.3s;
}

.upload-label:hover {
  background-color: #f0f0f0;
  border-color: #ccc;
}

.upload-input {
  display: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
}

.btn-outline {
  padding: 0.6rem 1.2rem;
  background: none;
  border: 1px solid #e75480;
  color: #e75480;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-outline:hover {
  background-color: #f8e1e7;
}

.btn-primary {
  padding: 0.6rem 1.2rem;
  background-color: #e75480;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.btn-primary:hover {
  background-color: #d64d7b;
}

@media (max-width: 992px) {
  .user-center-layout {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    margin-bottom: 1.5rem;
  }
  
  .user-info {
    padding: 1.5rem;
  }
  
  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    padding: 0.5rem;
  }
  
  .sidebar-link {
    padding: 0.8rem 1rem;
    flex: 1 0 auto;
    min-width: 150px;
  }
}

@media (max-width: 576px) {
  .user-info {
    flex-direction: column;
    text-align: center;
  }
  
  .sidebar-nav {
    flex-direction: column;
  }
  
  .sidebar-link {
    width: 100%;
  }
  
  .avatar-options {
    grid-template-columns: repeat(2, 1fr);
  }
}
</style>